package com.hncgy.xzf.jdapi.controller.index;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hncgy.xzf.jdapi.domain.index.Banners;
import com.hncgy.xzf.jdapi.mapper.index.BannersMapper;
import com.hncgy.xzf.jdapi.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 首页轮播图表 前端控制器
 * </p>
 *
 * @author 不会代码的蜡笔
 * @since 2025-10-31
 */
@RestController
@RequestMapping("/index/banners")
public class BannersController {

    @Autowired
    private BannersMapper bannersMapper;

    @RequestMapping("/list")
    public Result<List<Banners>> list(Banners banners) {
        try {
            QueryWrapper<Banners> bannersQueryWrapper = new QueryWrapper<>();
            bannersQueryWrapper.lambda()
                    .ne(Banners::getStatus, "inactive")
                    .like(StringUtils.hasText(banners.getBannerName()),
                            Banners::getBannerName,
                            banners.getBannerName());
            List<Banners> data = bannersMapper.selectList(bannersQueryWrapper);
            return Result.success(data);
        } catch (Exception e) {
            return Result.error("查询失败: " + e.getMessage());
        }
    }

}
